//
//  HDSystemHelpViewController.m
//  HDecoration
//
//  Created by 曹群 on 15/8/15.
//  Copyright (c) 2015年 HDecoration. All rights reserved.
//

#import "HDSystemHelpViewController.h"
#import "HDMenuView.h"
#import "HDSystemInfoScrollView.h"
#import "HDHelpCenterTableViewController.h"

@interface HDSystemHelpViewController ()
@property(nonatomic,strong)HDMenuView *menu;
@property(nonatomic,strong)UIScrollView *infoScrollView;
@property(nonatomic,strong)HDSystemInfoScrollView *aboutUsView;
@property(nonatomic,strong)HDSystemInfoScrollView *helpCenterView;
@property(nonatomic,strong)HDSystemInfoScrollView *feedbackView;
@property(nonatomic,strong)HDSystemInfoScrollView *verifySettingView;
@property(nonatomic,strong)HDSystemInfoScrollView *settingView;
@property(nonatomic,strong)HDHelpCenterTableViewController *helpCenter;
@property(nonatomic,strong)HDTextField *nameFiled;
@property(nonatomic,strong)HDTextField *phoneNumberField;
@property(nonatomic,strong)UITextView *feedbackTextView;
@property(nonatomic,strong)HDTextField *currentPassword;
@property(nonatomic,strong)HDTextField *aNewPassword;
@property(nonatomic,strong)HDTextField *confirmPassword;
@property(nonatomic,strong)HDTextField *settingPhoneNumber;
@property(nonatomic,strong)HDTextField *settingVerifyCode;
@property(nonatomic,strong)HDTextField *settingEmail;
@property(nonatomic,strong)UIButton *settingNextBtn;
@property(nonatomic,strong)UIButton *commitBtn;
@property(nonatomic,strong)UIButton *confirmBtn;
@property(nonatomic,strong)DOImageView *photo;
@property(nonatomic,strong)UIButton *verifyBtn;
@property NSTimer* time;
@end

@implementation HDSystemHelpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kContentViewColor;
    [self.view addSubview:self.menu];
    [self.view addSubview:self.infoScrollView];
    
    [[NSNotificationCenter defaultCenter]addObserver:self
                                            selector:@selector(checkInputFinished)
                                                name:UITextFieldTextDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self
                                            selector:@selector(checkInputFinished)
                                                name:UITextViewTextDidChangeNotification object:nil];
}

- (void)initNavigationBar
{
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
                                       initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                       target:nil action:nil];
    negativeSpacer.width = -10;
    UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 40, 40);
    [rightBtn setTitle:@"退出" forState:UIControlStateNormal];
    [rightBtn setTitleColor:kDarkGrayColor forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [rightBtn addTarget:self action:@selector(logoutAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, [[UIBarButtonItem alloc] initWithCustomView:rightBtn], nil];
}

- (void)logoutAction:(UIButton *)sender
{
    HDAppDelegate *appDelegate = (HDAppDelegate *)[UIApplication sharedApplication].delegate;
    [appDelegate loadLoginViewController];
}

- (void)selectMenuIndex:(int)index
{
    [self.infoScrollView setContentOffset:CGPointMake(APPFRAME.size.width*index, 0)];
}

- (void)checkInputFinished
{
    self.commitBtn.enabled = (self.nameFiled.text.length&&self.phoneNumberField.text.length&&self.feedbackTextView.text.length);
//    self.settingNextBtn.enabled = (self.settingPhoneNumber.text.length&&self.settingVerifyCode.text.length);
}

- (void)commitAction:(UIButton *)sender
{
    if (![HDUtil checkName:self.nameFiled.text]) {
        [netEngine showErrorAlertWithMsg:@"姓名格式不正确"];
        return;
    }
    if (![HDUtil checkMoblieNumber:self.phoneNumberField.text]) {
        [netEngine showErrorAlertWithMsg:@"手机格式不正确"];
        return;
    }
    NSDictionary* params=@{
                           @"send_id":netEngine.coachInfo.m_id,
                           @"sender":self.nameFiled.text,
                           @"phone":self.phoneNumberField.text,
                           @"comment":self.feedbackTextView.text,
                           @"type":[NSNumber numberWithInt:1],
                           };
    [netEngine RequestAskCompWithTarget:self.VctrID hudView:self.contentView Data:params];
}

- (void)verifyBtnAction:(UIButton *)sender
{
    NSDictionary* params=@{
                           @"mobile_no":self.settingPhoneNumber.text,
                           };
    [netEngine RequestVerifyCodeWithTarget:self.VctrID hudView:_infoScrollView Data:params];
}

-(void)timerAction
{
    self.verifyBtn.tag-=1;
    if (self.verifyBtn.tag<=0)
    {
        self.verifyBtn.enabled=YES;
        [self.verifyBtn setTitle:@"验证" forState:UIControlStateNormal];
    }
    else
    {
        [self.verifyBtn setTitle:[NSString stringWithFormat:@"%zis",self.verifyBtn.tag] forState:UIControlStateNormal];
    }
}

- (void)settingNextBtnAction:(UIButton *)sender
{
    if( _settingPhoneNumber.text.length)
    {
        if(![HDUtil checkMoblieNumber:_settingPhoneNumber.text])
        {
            [HDUtil showTipAlertWithMsg:@"手机号码不正确，请核对后继续"];
            return;
        }
        if (self.settingVerifyCode.text.length==0)
        {
            [HDUtil showTipAlertWithMsg:@"请输入验证码"];
            return;
        }
    }
    else
    {
        if (self.settingVerifyCode.text.length>0)
        {
            [HDUtil showTipAlertWithMsg:@"请输入手机号"];
            return;
        }
    }

    if(self.settingVerifyCode.text.length && ![netEngine.verifyCode isEqualToString:self.settingVerifyCode.text])
    {
        [HDUtil showTipAlertWithMsg:@"验证码校验错误,请核对后继续。"];
        return;
    }
  
    if (self.settingEmail.text.length && ![HDUtil isValidateEmail:self.settingEmail.text])
    {
        [HDUtil showTipAlertWithMsg:@"邮箱格式不对,请核对后继续。"];
        return;
    }
    
    self.settingView.alpha=0;
    [_infoScrollView addSubview:self.settingView];
    
    [UIView animateWithDuration:0.3 animations:^{
        self.verifySettingView.alpha = 0;
        self.settingView.alpha=1;
    }];
    
}

- (void)confirmAction:(UIButton *)sender
{
    if (self.aNewPassword.text.length && ![HDUtil checkPassword:self.aNewPassword.text]) {
        [netEngine showErrorAlertWithMsg:@"密码格式不正确，6-16位的字母、数字或符号的组合"];
        return;
    }
    if (self.confirmPassword.text.length && ![self.aNewPassword.text isEqualToString:self.confirmPassword.text])
    {
        [HDUtil showTipAlertWithMsg:@"校验密码不对，请核实后再试"];
        return;
    }
    
    NSMutableDictionary* params=[[NSMutableDictionary alloc] initWithCapacity:0];
    [params setObject:netEngine.coachInfo.m_id forKey:@"id"];
    
    if (self.settingVerifyCode.text.length)
    {
        [params setObject:self.settingVerifyCode.text forKey:@"verify_code"];
    }
    
    if (self.settingPhoneNumber.text.length)
    {
        [params setObject:self.settingPhoneNumber.text forKey:@"mobile_no"];
    }
    
    if (self.photo.image!=nil)
    {
        NSData* imgData=UIImagePNGRepresentation(self.photo.image);
        NSString *imageString = [imgData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
        [params setObject:imageString forKey:@"user_picture"];
    }
    
    if (self.confirmPassword.text.length)
    {
        [params setObject:self.confirmPassword.text forKey:@"new_password"];
    }
    if (self.currentPassword.text.length)
    {
        [params setObject:self.currentPassword.text forKey:@"password"];
    }
    if (self.settingEmail.text.length)
    {
        [params setObject:self.settingEmail.text forKey:@"email"];
    }
    
    [netEngine RequestUpdatePasswordWithTarget:self.VctrID hudView:self.infoScrollView Data:params];
}

- (void)tapAction
{
    [self.view endEditing:YES];
}

- (void)selectPhoto:(UIButton *)sender
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
        UIImagePickerController *imgPickerVC = [[UIImagePickerController alloc] init];
        imgPickerVC.view.backgroundColor = [UIColor whiteColor];
        [imgPickerVC setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        [imgPickerVC.navigationBar setBarStyle:UIBarStyleBlack];
        imgPickerVC.delegate = (id)self;
        imgPickerVC.navigationBar.tintColor = [UIColor whiteColor];
        //显示Image Picker
        imgPickerVC.allowsEditing = YES;
        [rootNavigation presentViewController:imgPickerVC animated:YES completion:nil];
        
    }else {
        NSLog(@"Album is not available.");
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"无法打开相册！" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
    }
}

-(void)updateViewController:(NSNotification *)note
{
    NSDictionary* dic=note.userInfo;
    if ([dic objectForKey:Receiver]==self.VctrID)
    {
       if(dic[@"UpdatePassword"]!=nil)
       {
           HDAppDelegate *appDelegate = (HDAppDelegate *)[UIApplication sharedApplication].delegate;
           [appDelegate loadLoginViewController];
       }
       if (dic[@"VerifyCode"]!=nil)
        {
            if (self.time)
            {
                [self.time invalidate];
                self.time=nil;
            }
            self.verifyBtn.tag=60;
            self.verifyBtn.enabled=NO;
            self.time=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
        }
    }
}

#pragma mark - UIImagePickerControllerDelegate  相册
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [rootNavigation dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
    UIImage *image= [info objectForKey:@"UIImagePickerControllerEditedImage"];
    UIImage *theImage = [self imageWithImageSimple:image scaledToSize:CGSizeMake(200.0, 200.0)];
    self.photo.image = theImage;
    [rootNavigation dismissViewControllerAnimated:YES completion:nil];
}

-(UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

#pragma mark - getters
- (HDMenuView *)menu
{
    if (!_menu) {
        _menu = [[HDMenuView alloc] initWithFrame:CGRectMake(0, 64, APPFRAME.size.width, 40) titleArray:@[@"关于我们",@"帮助中心",@"问题反馈",@"个人设置"]];
        _menu.selectedIndex = 0;
        _menu.delegate = (id)self;
    }
    return _menu;
}

- (UIScrollView *)infoScrollView
{
    if (!_infoScrollView) {
        _infoScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.menu.bottom, APPFRAME.size.width, APPFRAME.size.height-84)];
        _infoScrollView.scrollEnabled = NO;
        _infoScrollView.pagingEnabled = YES;
        _infoScrollView.contentSize = CGSizeMake(APPFRAME.size.width*4, _infoScrollView.height);
        [_infoScrollView addSubview:self.aboutUsView];
        [_infoScrollView addSubview:self.helpCenterView];
        [_infoScrollView addSubview:self.feedbackView];
        [_infoScrollView addSubview:self.verifySettingView];
    }
    return _infoScrollView;
}

- (HDSystemInfoScrollView *)aboutUsView
{
    if (!_aboutUsView) {
        _aboutUsView = [[HDSystemInfoScrollView alloc] initWithFrame:CGRectMake(0, 0, APPFRAME.size.width, APPFRAME.size.height-84)];
        NSString *aboutStr = @" 快马学车，是由安徽速考通网络科技股份有限公司全力打造的互联网学车应用服务，致力于建设“金牌服务”标准的互联网驾驶者培训考试平台，从车辆管理、教练监管、场地服务、客服流程、费用管控等方面，充分考虑用户群体的碎片化时间、学习能力、认知能力、经济能力，让学员从报名、学车、练车、考试、反馈、沟通等环节得到最优化的体验与服务。\n  在快马学车平台，学员可根据时间选择最快的城市报名，我们将全程安排服务对接，让异地报名考试最节约时间的旅游式体验服务；同时，学员可以自由选择教练、就近选择场地、合理选择时间、预约接送（让路途时间成为学车时间）、评价教练服务、线上完成支付。";
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:aboutStr];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.alignment = NSTextAlignmentLeft;
        paragraphStyle.lineSpacing = 6;  //行自定义行高度
        [paragraphStyle setFirstLineHeadIndent:15];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, aboutStr.length)];
        UILabel *aboutLabel = [[UILabel alloc] initWithFrame:CGRectMake(15 ,_aboutUsView.headerImage.bottom+15, _aboutUsView.width-30, 20)];
        aboutLabel.font = [UIFont systemFontOfSize:12];
        aboutLabel.numberOfLines = 0;
        aboutLabel.textColor = [UIColor hexStringToColor:@"#515151"];
        aboutLabel.attributedText = attributedString;
        [aboutLabel sizeToFit];
        [_aboutUsView addSubview:aboutLabel];
        
        UILabel *companyNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _aboutUsView.backgroundImage.height-50, _aboutUsView.backgroundImage.width, 20)];
        companyNameLabel.textAlignment = NSTextAlignmentCenter;
        companyNameLabel.textColor = [UIColor hexStringToColor:@"#adadad"];
        companyNameLabel.font = [UIFont systemFontOfSize:13];
        companyNameLabel.text = @"安徽速考通科技有限公司";
        [_aboutUsView.backgroundImage addSubview:companyNameLabel];
        
        UILabel *copyrightLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _aboutUsView.backgroundImage.height-30, _aboutUsView.backgroundImage.width, 20)];
        copyrightLabel.textAlignment = NSTextAlignmentCenter;
        copyrightLabel.textColor = [UIColor hexStringToColor:@"#adadad"];
        copyrightLabel.font = [UIFont systemFontOfSize:13];
        copyrightLabel.text = @"Copyright © 2015";
        [_aboutUsView.backgroundImage addSubview:copyrightLabel];
    }
    return _aboutUsView;
}

- (HDSystemInfoScrollView *)helpCenterView
{
    if (!_helpCenterView) {
        _helpCenterView = [[HDSystemInfoScrollView alloc] initWithFrame:CGRectMake(APPFRAME.size.width, 0, APPFRAME.size.width, APPFRAME.size.height-84)];
        self.helpCenter = [[HDHelpCenterTableViewController alloc] initWithStyle:UITableViewStylePlain];
        self.helpCenter.tableView.frame = CGRectMake(10, _helpCenterView.headerImage.bottom, _helpCenterView.backgroundImage.width-20, _helpCenterView.backgroundImage.height-_helpCenterView.headerImage.height-10);
        self.helpCenter.tableView.backgroundColor = [UIColor whiteColor];
        self.helpCenter.tableView.bounces = NO;
//        self.helpCenter.delegate = (id)self;
        [_helpCenterView.backgroundImage addSubview:self.helpCenter.tableView];
        self.helpCenter.dataArray = [@[
                                  @"1、关于报名",
                                  @"2、关于驾考中的限制条件",
                                  @"3、关于考试",
                                  @"4、关于练车",
                                  @"5、关于学车"] mutableCopy];
    }
    return _helpCenterView;
}

- (HDSystemInfoScrollView *)feedbackView
{
    if (!_feedbackView) {
        _feedbackView = [[HDSystemInfoScrollView alloc] initWithFrame:CGRectMake(APPFRAME.size.width*2, 0, APPFRAME.size.width, APPFRAME.size.height-84)];
        
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [_feedbackView addGestureRecognizer:tapGesture];
        
        UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _feedbackView.headerImage.bottom+10, _feedbackView.backgroundImage.width-20, 30)];
        tipLabel.textColor = kDarkGrayColor;
        tipLabel.numberOfLines = 0;
        tipLabel.font = [UIFont systemFontOfSize:13];
        tipLabel.text = @"感谢您的意见反馈，你的意见让我们进步更快！";
        [tipLabel sizeToFit];
        [_feedbackView.backgroundImage addSubview:tipLabel];
        _nameFiled = [[HDTextField alloc] initWithFrame:CGRectMake(10, tipLabel.bottom+10, _feedbackView.backgroundImage.width-20, 44)icon:@"头像" title:@"姓名："];
        _nameFiled.layer.borderColor = [UIColor colorWithRed:0.8824 green:0.8824 blue:0.8824 alpha:1].CGColor;
        _nameFiled.layer.borderWidth = 0.5;
        _nameFiled.layer.cornerRadius = 5;
        _nameFiled.placeholder = @"输入您的姓名";
        _nameFiled.font = [UIFont systemFontOfSize:15];
        [_feedbackView.backgroundImage addSubview:_nameFiled];
        
        _phoneNumberField = [[HDTextField alloc] initWithFrame:CGRectMake(10, _nameFiled.bottom+5, _feedbackView.backgroundImage.width-20, 44)icon:@"号码" title:@"手机："];
        _phoneNumberField.layer.borderColor = [UIColor colorWithRed:0.8824 green:0.8824 blue:0.8824 alpha:1].CGColor;
        _phoneNumberField.layer.borderWidth = 0.5;
        _phoneNumberField.layer.cornerRadius = 5;
        _phoneNumberField.placeholder = @"输入您的手机号码";
        _phoneNumberField.font = [UIFont systemFontOfSize:15];
        _phoneNumberField.text = netEngine.coachInfo.mobile_no;
        [_feedbackView.backgroundImage addSubview:_phoneNumberField];
        
        _feedbackTextView = [[UITextView alloc] initWithFrame:CGRectMake(10, _phoneNumberField.bottom+5, _feedbackView.backgroundImage.width-20, 100)];
        _feedbackTextView.layer.borderColor = [UIColor colorWithRed:0.8824 green:0.8824 blue:0.8824 alpha:1].CGColor;
        _feedbackTextView.layer.borderWidth = 0.5;
        _feedbackTextView.layer.cornerRadius = 5;
        _feedbackTextView.font = [UIFont systemFontOfSize:15];
        [_feedbackView.backgroundImage addSubview:_feedbackTextView];
        
        _commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _commitBtn.frame = CGRectMake(10, _feedbackTextView.bottom+20, _feedbackView.backgroundImage.width-20, 44);
        [_commitBtn setBackgroundImage:[UIImage imageNamed:@"提交按钮"] forState:UIControlStateNormal];
        [_commitBtn setTitle:@"提交" forState:UIControlStateNormal];
        [_commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _commitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_commitBtn addTarget:self action:@selector(commitAction:) forControlEvents:UIControlEventTouchUpInside];
        _commitBtn.enabled = NO;
        [_feedbackView.backgroundImage addSubview:_commitBtn];
        _feedbackView.backgroundImageHeight = _commitBtn.bottom+30;
    }
    return _feedbackView;
}

- (HDSystemInfoScrollView *)verifySettingView
{
    if (!_verifySettingView) {
        _verifySettingView = [[HDSystemInfoScrollView alloc] initWithFrame:CGRectMake(APPFRAME.size.width*3, 0, APPFRAME.size.width, APPFRAME.size.height-84)];
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [_verifySettingView addGestureRecognizer:tapGesture];
        
        [_verifySettingView addSubview:self.photo];
        self.settingPhoneNumber = [[HDTextField alloc] initWithFrame:CGRectMake(10, _verifySettingView.headerImage.bottom+40, _verifySettingView.backgroundImage.width-20, 44) icon:@"号码" title:nil];
        self.settingPhoneNumber.layer.borderColor = [UIColor colorWithRed:0.8824 green:0.8824 blue:0.8824 alpha:1].CGColor;
        _settingPhoneNumber.layer.borderWidth = 0.5;
        _settingPhoneNumber.layer.cornerRadius = 5;
        _settingPhoneNumber.placeholder = @"请输入手机号码";
        _settingPhoneNumber.font = [UIFont systemFontOfSize:15];
        [_verifySettingView.backgroundImage addSubview:_settingPhoneNumber];
        
        [_verifySettingView.backgroundImage addSubview:self.settingVerifyCode];
        
        _settingEmail = [[HDTextField alloc] initWithFrame:CGRectMake(10, _settingVerifyCode.bottom+5, _verifySettingView.backgroundImage.width-20, 44) icon:@"邮箱" title:nil];
        _settingEmail.layer.borderColor = [UIColor colorWithRed:0.8824 green:0.8824 blue:0.8824 alpha:1].CGColor;
        _settingEmail.layer.borderWidth = 0.5;
        _settingEmail.layer.cornerRadius = 5;
        _settingEmail.placeholder = @"请输入您的电子邮箱";
        _settingEmail.font = [UIFont systemFontOfSize:15];
        [_verifySettingView.backgroundImage addSubview:_settingEmail];
        
        _settingNextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _settingNextBtn.frame = CGRectMake(10, _settingEmail.bottom+40, _verifySettingView.backgroundImage.width-20, 44);
        [_settingNextBtn setBackgroundImage:[UIImage imageNamed:@"提交按钮"] forState:UIControlStateNormal];
        [_settingNextBtn setTitle:@"下一步" forState:UIControlStateNormal];
        [_settingNextBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _settingNextBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_settingNextBtn addTarget:self action:@selector(settingNextBtnAction:) forControlEvents:UIControlEventTouchUpInside];
//        _settingNextBtn.enabled = NO;
        [_verifySettingView.backgroundImage addSubview:_settingNextBtn];
        _verifySettingView.backgroundImageHeight = _settingNextBtn.bottom+50;
        _verifySettingView.showLogo=NO;
    }
    return _verifySettingView;
}

- (HDSystemInfoScrollView *)settingView
{
    if (!_settingView) {
        _settingView = [[HDSystemInfoScrollView alloc] initWithFrame:CGRectMake(APPFRAME.size.width*3, 0, APPFRAME.size.width, APPFRAME.size.height-84)];
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
        [_settingView addGestureRecognizer:tapGesture];
        
        _currentPassword = [[HDTextField alloc] initWithFrame:CGRectMake(10, _settingView.headerImage.bottom+30, _settingView.backgroundImage.width-20, 44) icon:@"密码" title:nil];
        _currentPassword.layer.borderColor = [UIColor colorWithRed:0.8824 green:0.8824 blue:0.8824 alpha:1].CGColor;
        _currentPassword.layer.borderWidth = 0.5;
        _currentPassword.layer.cornerRadius = 5;
        _currentPassword.secureTextEntry=YES;
        _currentPassword.placeholder = @"当前密码";
        _currentPassword.font = [UIFont systemFontOfSize:15];
        [_settingView.backgroundImage addSubview:_currentPassword];
        
        _aNewPassword = [[HDTextField alloc] initWithFrame:CGRectMake(10, _currentPassword.bottom+5, _settingView.backgroundImage.width-20, 44) icon:@"密码" title:nil];
        _aNewPassword.layer.borderColor = [UIColor colorWithRed:0.8824 green:0.8824 blue:0.8824 alpha:1].CGColor;
        _aNewPassword.layer.borderWidth = 0.5;
        _aNewPassword.layer.cornerRadius = 5;
        _aNewPassword.secureTextEntry=YES;
        _aNewPassword.placeholder = @"请输入您的新密码";
        _aNewPassword.font = [UIFont systemFontOfSize:15];
        [_settingView.backgroundImage addSubview:_aNewPassword];
        
        _confirmPassword = [[HDTextField alloc] initWithFrame:CGRectMake(10, _aNewPassword.bottom+5, _settingView.backgroundImage.width-20, 44) icon:@"密码" title:nil];
        _confirmPassword.layer.borderColor = [UIColor colorWithRed:0.8824 green:0.8824 blue:0.8824 alpha:1].CGColor;
        _confirmPassword.layer.borderWidth = 0.5;
        _confirmPassword.layer.cornerRadius = 5;
        _confirmPassword.secureTextEntry=YES;
        _confirmPassword.placeholder = @"请再次输入您的新密码";
        _confirmPassword.font = [UIFont systemFontOfSize:15];
        [_settingView.backgroundImage addSubview:_confirmPassword];
        
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _confirmBtn.frame = CGRectMake(10, _confirmPassword.bottom+40, _settingView.backgroundImage.width-20, 44);
        [_confirmBtn setBackgroundImage:[UIImage imageNamed:@"提交按钮"] forState:UIControlStateNormal];
        [_confirmBtn setTitle:@"确认修改" forState:UIControlStateNormal];
        [_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _confirmBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_confirmBtn addTarget:self action:@selector(confirmAction:) forControlEvents:UIControlEventTouchUpInside];
        [_settingView.backgroundImage addSubview:_confirmBtn];
        _settingView.backgroundImageHeight = _confirmBtn.bottom+50;
        _settingView.showLogo=NO;
    }
    return _settingView;
}

- (HDTextField *)settingVerifyCode
{
    if (!_settingVerifyCode) {
        _settingVerifyCode = [[HDTextField alloc] initWithFrame:CGRectMake(10, _settingPhoneNumber.bottom+5, _verifySettingView.backgroundImage.width-20, 44)icon:@"验证码" title:nil];
        _settingVerifyCode.layer.borderColor = [UIColor colorWithRed:0.8824 green:0.8824 blue:0.8824 alpha:1].CGColor;
        _settingVerifyCode.layer.borderWidth = 0.5;
        _settingVerifyCode.layer.cornerRadius = 5;
        _settingVerifyCode.placeholder = @"请输入验证码";
        _settingVerifyCode.font = [UIFont systemFontOfSize:15];
        UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 44)];
        UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, 5, 0.5, 34)];
        line.image = [UIImage imageNamed:@"dot"];
        self.verifyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.verifyBtn.frame = CGRectMake(10, 7, 60, 30);
        [self.verifyBtn setBackgroundImage:[UIImage imageNamed:@"验证"] forState:UIControlStateNormal];
        [self.verifyBtn setTitle:@"验证" forState:UIControlStateNormal];
        [self.verifyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.verifyBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [self.verifyBtn addTarget:self action:@selector(verifyBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        [rightView addSubview:line];
        [rightView addSubview:self.verifyBtn];
        _settingVerifyCode.rightViewMode = UITextFieldViewModeAlways;
        _settingVerifyCode.rightView = rightView;
    }
    return _settingVerifyCode;
}

- (DOImageView *)photo
{
    if (!_photo) {
        _photo = [[DOImageView alloc] initWithFrame:CGRectMake((_verifySettingView.width-76)/2.0, _verifySettingView.headerImage.bottom-40, 76, 76)];
        _photo.userInteractionEnabled = YES;
        _photo.layer.cornerRadius = 38;
        _photo.clipsToBounds = YES;
        _photo.layer.masksToBounds = YES;
        _photo.layer.borderColor = [UIColor whiteColor].CGColor;
        _photo.layer.borderWidth = 5;
        _photo.contentMode = UIViewContentModeScaleAspectFit;
        _photo.imgURLStr = netEngine.coachInfo.user_picture;
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectPhoto:)];
        [_photo addGestureRecognizer:tapGesture];
    }
    return _photo;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
